package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.Environment;
import com.java110.mall.cart.bmo.housekeepingFeeType.IDeleteHousekeepingFeeTypeBMO;
import com.java110.mall.cart.bmo.housekeepingFeeType.IGetHousekeepingFeeTypeBMO;
import com.java110.mall.cart.bmo.housekeepingFeeType.ISaveHousekeepingFeeTypeBMO;
import com.java110.mall.cart.bmo.housekeepingFeeType.IUpdateHousekeepingFeeTypeBMO;
import com.java110.dto.housekeeping.HousekeepingFeeTypeDto;
import com.java110.po.housekeeping.HousekeepingFeeTypePo;

import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingFeeType")
public class HousekeepingFeeTypeApi {

    @Autowired
    private ISaveHousekeepingFeeTypeBMO saveHousekeepingFeeTypeBMOImpl;
    @Autowired
    private IUpdateHousekeepingFeeTypeBMO updateHousekeepingFeeTypeBMOImpl;
    @Autowired
    private IDeleteHousekeepingFeeTypeBMO deleteHousekeepingFeeTypeBMOImpl;

    @Autowired
    private IGetHousekeepingFeeTypeBMO getHousekeepingFeeTypeBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /housekeepingFeeType/saveHousekeepingFeeType
     * @path /app/housekeepingFeeType/saveHousekeepingFeeType
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveHousekeepingFeeType", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingFeeType(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "typeName", "请求报文中未包含typeName");
        Assert.hasKeyAndValue(reqJson, "isShow", "请求报文中未包含isShow");


        HousekeepingFeeTypePo housekeepingFeeTypePo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeTypePo.class);
        return saveHousekeepingFeeTypeBMOImpl.save(housekeepingFeeTypePo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /housekeepingFeeType/updateHousekeepingFeeType
     * @path /app/housekeepingFeeType/updateHousekeepingFeeType
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateHousekeepingFeeType", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingFeeType(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();

        Assert.hasKeyAndValue(reqJson, "typeName", "请求报文中未包含typeName");
        Assert.hasKeyAndValue(reqJson, "isShow", "请求报文中未包含isShow");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "feeTypeCd不能为空");


        HousekeepingFeeTypePo housekeepingFeeTypePo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeTypePo.class);
        return updateHousekeepingFeeTypeBMOImpl.update(housekeepingFeeTypePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingFeeType/deleteHousekeepingFeeType
     * @path /app/housekeepingFeeType/deleteHousekeepingFeeType
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteHousekeepingFeeType", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingFeeType(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "feeTypeCd不能为空");


        HousekeepingFeeTypePo housekeepingFeeTypePo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeTypePo.class);
        return deleteHousekeepingFeeTypeBMOImpl.delete(housekeepingFeeTypePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingFeeType/queryHousekeepingFeeType
     * @path /app/housekeepingFeeType/queryHousekeepingFeeType
     * @param shopId 小区ID
     * @return
     */
    @RequestMapping(value = "/queryHousekeepingFeeType", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingFeeType(@RequestParam(value = "shopId") String shopId,
                                                      @RequestParam(value = "typeName", required = false) String typeName,
                                                      @RequestParam(value = "isShow", required = false) String isShow,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        HousekeepingFeeTypeDto housekeepingFeeTypeDto = new HousekeepingFeeTypeDto();
        housekeepingFeeTypeDto.setPage(page);
        housekeepingFeeTypeDto.setRow(row);
        housekeepingFeeTypeDto.setShopId(shopId);
        housekeepingFeeTypeDto.setTypeName(typeName);
        housekeepingFeeTypeDto.setIsShow(isShow);
        return getHousekeepingFeeTypeBMOImpl.get(housekeepingFeeTypeDto);
    }
}
